package com.sina.shop.core.exception;


import com.sina.shop.util.ResultCode;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * 段浩杰   2017-09-13-10:50
 */
public class ShopCustomException extends RuntimeException {
    private ResultCode resultCode = ResultCode.unknown;


    public ShopCustomException(ResultCode resultCode) {
        this.resultCode = resultCode;
    }

    public ShopCustomException(ResultCode resultCode, String message) {
        super(message);
        this.resultCode = resultCode;
    }

    public ShopCustomException(ResultCode resultCode, Throwable cause) {
        super(cause);
        this.resultCode = resultCode;
    }

    public ShopCustomException(ResultCode resultCode, String message, Throwable cause) {
        super(message, cause);
        this.resultCode = resultCode;
    }

    public ResultCode getResultCode() {
        return resultCode;
    }

    @Override
    public String toString() {
        String s = getClass().getName();
        String message = getLocalizedMessage();
        message = message != null ? getResultCode() + message : message;
        return (message != null) ? (s + ": " + message) : s;
    }
}
